home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Communications / pcomm / Source / s_extrnl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-12  |  4.0 KB  |  175 lines

  1. /*
  2.  * Display the external protocol setup, query for changes.  A non-zero
  3.  * return code means something was changed.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <curses.h>
  8. #include "config.h"
  9. #include "extrnl.h"
  10. #include "misc.h"
  11.  
  12. int
  13. ext_setup()
  14. {
  15.     extern char *null_ptr;
  16.     WINDOW *ext_win, *newwin();
  17.     int i, ret_code;
  18.     static int ext_prompt();
  19.     char *str, *get_str();
  20.     static void disp_ext();
  21.  
  22.     ext_win = newwin(23, 80, 0, 0);
  23.  
  24.     horizontal(ext_win, 0, 0, 27);
  25.     mvwattrstr(ext_win, 0, 28, A_BOLD, "External Protocol Setup");
  26.     horizontal(ext_win, 0, 52, 27);
  27.     mvwaddstr(ext_win, 3, 36, "UPLOAD");
  28.     mvwaddstr(ext_win, 5, 8, "Name");
  29.     mvwaddstr(ext_win, 5, 21, "Command line");
  30.     mvwaddstr(ext_win, 5, 54, "Requires file list?");
  31.     mvwaddstr(ext_win, 10, 35, "DOWNLOAD");
  32.     mvwaddstr(ext_win, 12, 8, "Name");
  33.     mvwaddstr(ext_win, 12, 21, "Command line");
  34.     mvwaddstr(ext_win, 12, 54, "Requires file list?");
  35.                     /* display the current list */
  36.     disp_ext(ext_win);
  37.  
  38.     horizontal(ext_win, 19, 0, 80);
  39.     mvwattrstr(ext_win, 20, 0, A_BOLD, "OPTION ==> ");
  40.     mvwaddstr(ext_win, 20, 58, "Press <ESC> to return");
  41.     wmove(ext_win, 20, 12);
  42.     touchwin(ext_win);
  43.     wrefresh(ext_win);
  44.                     /* get the option */
  45.     ret_code = 0;
  46.     while ((str = get_str(ext_win, 1, "1234356", "")) != NULL) {
  47.         switch(*str) {
  48.             case '1':
  49.                 if (ext_prompt(ext_win, 1, 0, 6))
  50.                     ret_code++;
  51.                 break;
  52.             case '2':
  53.                 if (ext_prompt(ext_win, 1, 1, 7))
  54.                     ret_code++;
  55.                 break;
  56.             case '3':
  57.                 if (ext_prompt(ext_win, 1, 2, 8))
  58.                     ret_code++;
  59.                 break;
  60.             case '4':
  61.                 if (ext_prompt(ext_win, 0, 0, 13))
  62.                     ret_code++;
  63.                 break;
  64.             case '5':
  65.                 if (ext_prompt(ext_win, 0, 1, 14))
  66.                     ret_code++;
  67.                 break;
  68.             case '6':
  69.                 if (ext_prompt(ext_win, 0, 2, 15))
  70.                     ret_code++;
  71.                 break;
  72.         }
  73.         mvwaddstr(ext_win, 20, 12, "  ");
  74.         clear_line(ext_win, 21, 0, FALSE);
  75.         clear_line(ext_win, 22, 0, FALSE);
  76.         wmove(ext_win, 20, 12);
  77.         wrefresh(ext_win);
  78.     }
  79.     /*
  80.      * Recalculate the number of entries.  Please notice that if you
  81.      * create an empty entry (a hole), all entries after that are ignored.  
  82.      * The software doesn't compact the holes out.. you're on your own.
  83.      */
  84.     if (ret_code) {
  85.         for (i=0; i<3; i++) {
  86.             if (extrnl->name[1][i] == null_ptr)
  87.                 break;
  88.         }
  89.         extrnl->up_entries = i;
  90.  
  91.         for (i=0; i<3; i++) {
  92.             if (extrnl->name[0][i] == null_ptr)
  93.                 break;
  94.         }
  95.         extrnl->dn_entries = i;
  96.     }
  97.     delwin(ext_win);
  98.     return(ret_code);
  99. }
  100.  
  101. /*
  102.  * Display the current list of external file transfer programs.
  103.  */
  104.  
  105. static void
  106. disp_ext(win)
  107. WINDOW *win;
  108. {
  109.     int i, up, entry, line;
  110.  
  111.     up = 1;
  112.     line = 6;
  113.     for (i=0; i<6; i++) {
  114.         if (i < 3)
  115.             entry = i;
  116.         else {
  117.             up = 0;
  118.             entry = i-3;
  119.             line = 10;
  120.         }
  121.         mvwprintw(win, i+line, 5, "%d) %-12.12s %-40.40s  %c\n",
  122.          i+1, extrnl->name[up][entry], extrnl->command[up][entry],
  123.          extrnl->prompt[up][entry]);
  124.     }
  125.     return;
  126. }
  127.  
  128. /*
  129.  * Prompt for the info in the database.  A non-zero return code means
  130.  * that something was changed.  To delete the line, you enter a single
  131.  * space character at the first prompt.
  132.  */
  133.  
  134. static int
  135. ext_prompt(win, up, entry, line)
  136. WINDOW *win;
  137. int up, entry, line;
  138. {
  139.     extern char *v_yn[], *null_ptr;
  140.     char *ans, t_name[80], t_command[80], *str_prompt(), *str_rep();
  141.     char *strcpy(), *menu_prompt();
  142.  
  143.                     /* get temp name */
  144.     if ((ans = str_prompt(win, line, 8, "Protocol name", "")) == NULL)
  145.         return(0);
  146.  
  147.     strcpy(t_name, ans);
  148.     clear_line(win, 21, 0, FALSE);
  149.                     /* are we zapping the line */
  150.     if (ans == null_ptr) {
  151.         extrnl->name[up][entry] = null_ptr;
  152.         extrnl->command[up][entry] = null_ptr;
  153.         extrnl->prompt[up][entry] = 'N';
  154.         return(1);
  155.     }
  156.                     /* get temp command */
  157.     if ((ans = str_prompt(win, line, 21, "Command line", "")) == NULL)
  158.         return(0);
  159.  
  160.     strcpy(t_command, ans);
  161.     clear_line(win, 21, 0, FALSE);
  162.  
  163.                     /* get temp prompt */
  164.     if ((ans = menu_prompt(win, line, 63, "Does it require a file list", v_yn)) == NULL)
  165.         return(0);
  166.  
  167.     wrefresh(win);
  168.                     /* store 'em for real */
  169.     extrnl->name[up][entry] = str_rep(extrnl->name[up][entry], t_name);
  170.     extrnl->command[up][entry] = str_rep(extrnl->command[up][entry], t_command);
  171.     extrnl->prompt[up][entry] = *ans;
  172.  
  173.     return(1);
  174. }
  175.